<?php
namespace Test\Client;

error_reporting(E_ALL);

require_once __DIR__ . '/../../Thrift/ClassLoader/ThriftClassLoader.php';

use Thrift\ClassLoader\ThriftClassLoader;

$genDir = __DIR__ . '/gen-php';

$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ );
$loader->registerDefinition('ThriftGen', $genDir );
$loader->register();

use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TBufferedTransport;
use Thrift\Exception\TException;
use ThriftGen\Test\Service\TestServiceClient;

try
{
    if(array_search('--http', $argv))
    {
        $socket = new THttpClient('192.168.2.11', 9091, '/Server.php');
    }
    else
    {
        $socket = new TSocket('192.168.2.11', 9090);
    }
    $transport = new TBufferedTransport($socket, 1024, 1024);
    $protocol = new TBinaryProtocol($transport);
    $client = new TestServiceClient($protocol);

    $transport->open();

    $result = $client->getUserName(5028);
    var_dump($result);
    $result = $client->getUserInfo(5028);
    var_dump($result);
    $client->test(5028);
    echo "Finished\n";

    $transport->close();
}
catch(TException $tx)
{
    print 'TException: ' . $tx->getMessage() . "\n";
}